#ifndef THERMALCAM_H
#define THERMALCAM_H


#include <iostream>   	//C++相关的头文件
#include <sstream>	//与fstream类型类似，头文件sstream中定义的类型都继承iostream头文件中定义的类型

//mkdir
#include <sys/stat.h>
#include <stdio.h>    	//C相关的头文件
#include <string.h>   	//包含比如strcpy、strcat之类的字符串处理函数
#ifdef _WIN32
    #include <windows.h>		//windows下Sleep头文件
#elif defined(__linux__) || defined(__APPLE__)
    #include <unistd.h>		//linux下sleep头文件std::string hearBeatInit(const string robotName);
#endif
				

#include "worker.h"
#include "HCNetSDK.h"   //海康sdk最重要的头文件
#include "iniFile.h"

#define  HPR_OK 0
#define  HPR_ERROR -1
//获取 测温能力集
#define ISAPI_OUT_LEN 3*1024*1024
#define ISAPI_STATUS_LEN 8*1024

struct ThermalCameraArgs{
    std::string iniPath = "null";
    RT::Worker *workerPtr = NULL;
};

class ThermalCamera{
public:
    //thermal();
    ThermalCamera(const ThermalCameraArgs args);
    ~ThermalCamera();
    //int mhckRun_ftp();
    int mHckRun_tcp();
    void closeHikSDK();

    string m_selfName;

    static std::string mCreateJson_alarm(const int imgBuffSize, const float fx, const float fy);
    static std::string mCreateJson_deviceInfo(const float max, const float min, const float ave
                                                , const float diff, const int pos, const string time
                                                , const int imgSize);
    static int mCapPicture(const int inLUserID, const int channel, std::string inOutPicturePath);                                       
private:
    RT::Worker *m_workerPtr = NULL;

    int mPort;
    std::string mIP;
    std::string mUserName;
    std::string mPassword;
    int m_rule;

    int m_imageBuffSize;    //预设红外图像的内存大小
    int m_realtemp_interval;    //实时温度发送间隔
    char  m_szStatusBuf[ISAPI_STATUS_LEN];
    char  m_OutBuf[ISAPI_OUT_LEN];

    std::string mhckLibDir;
    // //基础功能函数
    int mInitHikSDK();
    static void mSDK_Version();
    static int mDemo_GetDeviceState(LONG lUserID);
    int mGetAbility_thermal(const int lUserID);
    int mGetThermMode(const int lUserID);
    int setThermParams(const int lUserID);
        int setThermParams_sys(const int lUserID);
        int setThermParams_basicParam(const int lUserID);
 
    // //扩展功能函数

    //温度报警
    LONG mLHandle_alarm = -1;      //报警布防句柄
    // int mAlarmDetect(const int lUserId);
    int mAlarmDetect_tcp(const int lUserId);
        bool mb_alarmDetect; // 是否温度报警
    int closeAlarmDetect(const int lHandle_alarm);

    //实时温度检测
    LONG mLHandle_realtemp = -1;	//实时温度检测句柄
    // int RealTempDetect(const int lUserId);
    int mRealTempDetect_tcp(const int lUserId);
        bool mb_realTempDetect;     //是否实时温度检测
        bool mIsSendRealThermalImg;
        int m_sendImgInterval;
    int closeRealTempDetect(const int lHandle_realtemp);

    bool m_setThermalSysParams;
    //system params config
    BYTE    m_channelName[50];      // show in thermal image
    DWORD   m_dwShowChanName = 1;
    DWORD   m_dwShowOsd = 1;    //1; display osd
    BYTE    m_byOSDType = 0;    //0: year-month-day
    BYTE    m_byDispWeek = 0;   //1: display  week

    //测温基本参数配置
    NET_DVR_FIREDETECTION_CFG m_struFireDetection;
    BYTE    m_byThermometryUnit = 0;    //测温单位（所有测温配置功能中温度参数对应的单位）: 0- 摄氏度（℃），1- 华氏度（℉），2- 开尔文(K)     
    BOOL	m_bEnbaleThermometry;
    BOOL	m_bStreamOverlay;
    BOOL    m_bPictureOverlay;          //抓图是否叠加温度信息：0- 否，1- 是 
    BYTE	m_bySensitivity;
    BYTE    m_comTemperatureColor;
    int     m_iHighTemperature;     //high valude   -273~10000
    int     m_iLowTemperature;      //low value     -273~10000
    BYTE    m_comDistanceUnit;           // 距离单位: 0- 米(m)，1- 英尺(feet)，2-厘米（cm）  
    BYTE    m_cmbFireImageModea;
    BYTE    m_cmbThermometryCurve;
    float   m_fThernomertryEmissivity;      //发射率(发射率 精确到小数点后两位)[0.01, 1.00](即：物体向外辐射能量的本领)
    BYTE    m_byEnviroHumidity;
    int     m_iEnviroTemperature;
    int     m_iCorrectionVolume;
    BOOL    m_bChkCenterSpecialPoint;
    BOOL    m_bChkHighestSpecialPoint;
    BOOL    m_bChkLowestSpecialPoint;
    BOOL	m_bChkReflectiveEnabled;
    DWORD	m_dwDistanceMeter;
    float   m_fReflectiveTemp;
    BOOL    m_bShowTempStripEnable;
    float   m_fAlarmVal;                              //***//66 报警温度阈值，-100.0-1000.0度（精确到小数点后一位)
    float   m_fAlertVal;                              //***//33 预警温度阈值，-100.0-1000.0度（精确到小数点后一位）
    float   m_ThermalOpticalTransmittance;            //光学透过率, 精确到小数点后3位，范围0.001-1.000，默认1.000
    float   m_externalOpticsWindowCorrection;   
    BOOL    m_displayMaxTemperatureEnabled ;             // 显示最高温 0-不显示 1-显示
    BOOL    m_displayMinTemperatureEnabled ;             // 显示最低温 0-不显示 1-显示
    BOOL    m_displayAverageTemperatureEnabled;         // 显示平均温 0-不显示 1-显示
    BYTE    m_thermometryInfoDisplayposition;        // 测温信息显示位置 0-保留 1-跟随规则 2-屏幕左上角
    int		m_AlertFilteringTime;
    int     m_AlarmFilteringTime;
    BYTE    m_displayTemperatureInOpticalChannelEnabled;
    BOOL    m_displayCentreTemperatureEnabled;

   
};

#endif

